package testWork;


import java.util.ArrayList;
import java.util.List;

public class test3 {
    List<List<Integer>> res;
    public List<List<Integer>> permute(int[] nums) {
        res = new ArrayList<>();
        int[] used = new int[nums.length];
        List<Integer> list = new ArrayList<>();
        dfs(list,0,nums,used);
        return res;
    }

    public void dfs(List<Integer> list,int k,int[] nums,int[] used){
        if(k==nums.length-1){
            list.add(nums[k]);
            //有问题
            List<Integer> t = new ArrayList(list);
            res.add(t);
            return;
        }
        for(int i = 0;i<nums.length;i++){
            if(used[i]==0){
                list.add(nums[i]);
                used[i]=1;
                dfs(list,k+1,nums,used);
                used[i]=0;
                list.remove(list.size()-1);
            }
        }
        return;

    }

    public static void main(String[] args) {
        test3 test3 = new test3();
        test3.permute(new int[]{1,2,3});
    }



}
